#ifndef PLANE_H
#define PLANE_H

#pragma once
#include "Vector.h"
#include "Color.h"
#include "Object.h"
#include <iostream>
class Plane : public Object{
public:
	Color color;
	Vector normal;
	Vector intersection;
	Vector plane_v1,plane_v2,plane_v3,plane_v4;
	string plane_name;
	float distance_fromplane_toscene;
	float D;
	Plane(): distance_fromplane_toscene(0.0), color(0.5,0.5,0.5,0), normal(1,0,0) {}
	Plane(const Vector &p1,const Vector &p2, const Vector &p3,const Vector &p4,const Color& col,const float& DtoScene
		,const string& name): 
		plane_v1(p1),plane_v2(p2),plane_v3(p3),plane_v4(p4), color(col), distance_fromplane_toscene(DtoScene),plane_name(name){D = 0;}

	bool findIntersection(Ray ray){
		float denominator = ray.Direction*normal;
		D = plane_v1*normal;
		if(denominator==0)
			return false;
		float t = -((ray.origin*normal)-D)/denominator;
		if(t>0)
		{
			intersection = ray.origin + (t*ray.Direction);
			
			return true;
		}
		return false;
	}
};

#endif